home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / rkeyboar.cpt / Reactive Keyboard ƒ / help.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-27  |  7.1 KB  |  291 lines

  1. #include "MacIncludes.h"
  2. #include "hlp.h"
  3. #include "help.h"
  4. #include "utl.h"
  5. #include "Rk.h"
  6.  
  7. /*______________________________________________________________________
  8.  
  9.     Global Variables.
  10. _____________________________________________________________________*/
  11.  
  12.  
  13.         WindowPtr        HelpWindow = nil;        /* ptr to help window */
  14. static WindowRecord        HelpWRecord;            /* help window record */
  15. static WindowObject        HelpWindObject;            /* help window object */
  16. static rpp_PrtBlock        helpPrint;                /* help window print block */
  17. static Boolean            MenuPick=true;                /* true if command was via menu pick */
  18.  
  19.  
  20. /*______________________________________________________________________
  21.  
  22.     Click - Process Mouse Down Event.
  23.     
  24.     Entry:        where = mouse down location, local coords.
  25.                     modifiers = modifier keys.
  26. _____________________________________________________________________*/
  27.  
  28. static void Click (Point where, short modifiers)
  29.  
  30. {
  31. #pragma unused (modifiers)
  32.  
  33.     hlp_Click(where);
  34. }
  35.  
  36. /*______________________________________________________________________
  37.  
  38.     Help - Process Mouse Down Event in Help Mode.
  39.     
  40.     Entry:        where = mouse down location, local coords.
  41. _____________________________________________________________________*/
  42.  
  43.  
  44. static void Help (Point where)
  45.  
  46. {
  47.     Rect        tcRect;            /* tcon rectangle */
  48.  
  49.     hlp_GetTconRect(&tcRect);
  50.     tcRect.top -= 15;
  51.     help_Open(PtInRect(where, &tcRect) ? tagHelpTcon : tagHelpWind);
  52. }
  53.     
  54. /*______________________________________________________________________
  55.  
  56.     Close - Close Window.
  57. _____________________________________________________________________*/
  58.  
  59.  
  60. static void Close (void)
  61.  
  62. {
  63.     hlp_Close();
  64.     CloseWindow(HelpWindow);
  65.     HelpWindow = nil;
  66. }
  67.     
  68. /*______________________________________________________________________
  69.  
  70.     Save - Process Save Command.
  71.     
  72.     Exit:        function result = true (nobody cares if the user canceled!)
  73. _____________________________________________________________________*/
  74.  
  75.  
  76. static Boolean Save (void)
  77.  
  78. {
  79.     Str255            prompt;            /* SFPutFile prompt string */
  80.     Str255            defName;        /* default name for help save dlog */
  81.     OSErr            rCode;            /* result code */
  82.     Str255            rCodeStr;        /* result code as a string */
  83.     
  84.     /* Get the prompt string and default file name. */
  85.     
  86.     GetIndString(prompt, rNameStrings, iPromptStr);
  87.     GetIndString(defName, rNameStrings, iDefNameStr);
  88.         
  89.     /* Call hlp_Save to save the file. */
  90.     
  91.     rCode = hlp_Save(prompt, defName, 'MSWD', MenuPick);
  92.     
  93.     /* Handle errors. */
  94.     
  95.     if (rCode) {
  96.         if (rCode == dskFulErr) {
  97.             utl_StopAlert(eDiskFull, nil, 0);
  98.         } else if (rCode == fLckdErr) {
  99.             utl_StopAlert(eFileLocked, nil, 0);
  100.         } else {
  101.             NumToString(rCode, rCodeStr);
  102.             ParamText(rCodeStr, nil, nil, nil);
  103.             utl_StopAlert(eUnexpectedSave, nil, 0);
  104.         };
  105.     };
  106.         
  107.     return true;
  108. }
  109.     
  110. /*______________________________________________________________________
  111.  
  112.     PageSetup - Process Page Setup Command.
  113.     
  114.     Exit:        function result = error code.
  115. _____________________________________________________________________*/
  116.  
  117.  
  118. static OSErr PageSetup (void)
  119.  
  120. {
  121.     Boolean            canceled;
  122.     
  123.     misc_ValPrint(&helpPrint, false);
  124.     helpPrint.menuPick = MenuPick;
  125.     return rpp_StlDlog(&helpPrint, &canceled);
  126. }
  127.     
  128. /*______________________________________________________________________
  129.  
  130.     Print - Process Print Command.
  131.     
  132.     Entry:    printOne = true if Print One command.
  133.     
  134.     Exit:        function result = error code.
  135. _____________________________________________________________________*/
  136.  
  137.  
  138. static OSErr Print (Boolean printOne)
  139.  
  140. {
  141.     Str255            titleTmpl;    /* template for date, time, pnum in headers */
  142.     Str255            docName;        /* document name */
  143.     
  144.     GetIndString(titleTmpl, rNameStrings, ihlpDocTmpl);
  145.     GetIndString(docName, rNameStrings, ihlpDocTitle);
  146.     helpPrint.title = docName;
  147.     helpPrint.titleTmpl = titleTmpl;
  148.     helpPrint.docName = docName;
  149.     misc_ValPrint(&helpPrint, false);
  150.     helpPrint.menuPick = MenuPick;
  151.     return hlp_Print(&helpPrint, printOne);
  152. }
  153.     
  154. /*______________________________________________________________________
  155.  
  156.     Adjust - Adjust Menus.
  157. _____________________________________________________________________*/
  158.  
  159.  
  160. static void Adjust (void)
  161.  
  162. {
  163.     MenuHandle                fileM;                    /* handle to file menu */
  164.     MenuHandle                editM;                    /* handle to edit menu */
  165.     
  166.     fileM = GetMHandle(mFile);
  167.     editM = GetMHandle(mEdit);
  168.     EnableItem(fileM, iClose);
  169.     EnableItem(fileM, iSaveAs);
  170.  
  171.     DisableItem(fileM, iPageSetup);
  172.     DisableItem(fileM, iPrint);
  173.     DisableItem(fileM, iNew);
  174.     DisableItem(fileM, iSave);
  175.     DisableItem(fileM, iOpen);
  176.     DisableItem(fileM, iPrime);
  177.  
  178.     /* printing won't work for now */
  179.  
  180.     DisableItem(editM, 0);
  181.     
  182. }
  183.  
  184. /*______________________________________________________________________
  185.  
  186.     DrawTconTitle - Draw Table of Contents Title.
  187. _____________________________________________________________________*/
  188.  
  189.  
  190. static void DrawTconTitle ()
  191.  
  192. {
  193.     Str255            str;                /* title */
  194.     short            h;                    /* horizontal coord of title */
  195.     Rect            tconRect={25, 386, 267, 483};
  196.  
  197.     GetIndString(str, rNameStrings, iTConTitle);
  198.     TextFace(bold);
  199.     h = (tconRect.left + tconRect.right
  200.         - StringWidth(str)) >> 1;
  201.     MoveTo(h, tconRect.top-5);
  202.     DrawString(str);
  203.     TextFace(normal);
  204. }
  205.     
  206. /*______________________________________________________________________
  207.  
  208.     help_Open - Open Help Window.
  209.     
  210.     Entry:        tag = Tagged line to jump to, or 0 if none.
  211. _____________________________________________________________________*/
  212.  
  213.  
  214. void help_Open (short tag)
  215.  
  216. {
  217.     hlp_PBlock        p;                /* hlp_Open param block. */
  218.     short            fNum;            /* font number */
  219.                                      /* 288*/
  220.     Rect            docRect={10, 12, 328, 374};
  221.     Rect            tconRect={25, 386, 267, 483};
  222.     
  223.  
  224.     /* If the window is already open, activate it and jump to the tag. */
  225.     
  226.     if (HelpWindow) {
  227.         SelectWindow(HelpWindow);
  228.         if (tag) hlp_Jump(tag);
  229.         return;
  230.     };
  231.     
  232.     /* Get the help window and restore its state. */
  233.     
  234.     HelpWindow = utl_GetNewWindow(rAboutWin, (Ptr)&HelpWRecord, (WindowPtr)-1);
  235.     SetPort(HelpWindow);
  236.     
  237.     /* Initialize the window object. */
  238.     
  239.     ((WindowPeek)HelpWindow)->refCon = (long)&HelpWindObject;
  240.     HelpWindObject.windKind = helpWind;
  241.     SetRect(&HelpWindObject.sizeRect, HelpWindow->portRect.right, 
  242.         100, HelpWindow->portRect.right, 0x7fff);
  243.     HelpWindObject.update = hlp_Update;
  244.     HelpWindObject.activate = hlp_Activate;
  245.     HelpWindObject.deactivate = hlp_Deactivate;
  246.     HelpWindObject.resume = nil;
  247.     HelpWindObject.suspend = nil;
  248.     HelpWindObject.click = Click;
  249.     HelpWindObject.help = Help;
  250.     HelpWindObject.grow = hlp_Grow;
  251.     HelpWindObject.zoom = hlp_Zoom;
  252.     HelpWindObject.key = hlp_Key;
  253.     HelpWindObject.close = Close;
  254.     HelpWindObject.disk = nil;
  255.     HelpWindObject.save = Save;
  256.     HelpWindObject.pageSetup = PageSetup;
  257.     HelpWindObject.print = Print;
  258.     HelpWindObject.edit = nil;
  259.     HelpWindObject.adjust = Adjust;
  260.     HelpWindObject.periodic = nil;
  261.     HelpWindObject.dialogPre = nil;
  262.     HelpWindObject.dialogPost = nil;
  263.     
  264.     /* Initialize hlp_Open param block. */
  265.     
  266.     if (!utl_GetFontNumber("\pGeneva", &fNum)) fNum = applFont;
  267.     p.scrollLine = 0;
  268.     p.firstStrID = firstDocID;
  269.     p.listDefID = lDefID;
  270.     p.textRect = docRect;
  271.     p.fontNum = fNum;
  272.     p.fontSize = 9;
  273.     p.tabConID = tconID;
  274.     p.tabConRect = tconRect;
  275.     p.tabConFNum = fNum;
  276.     p.tabConFSize = 9;
  277.     p.tabConLSep = 12;
  278.     p.tag = tag;
  279.     p.tagRezID = tagID;
  280.     p.cellRezID = cellID;
  281.     p.cellOption = 2;
  282.     p.extraUpdate = DrawTconTitle;
  283.     
  284.     /* Call hlp_Open to complete the open. */
  285.     
  286.     hlp_Open(HelpWindow, &p);
  287. }
  288.  
  289.  
  290.  
  291.